﻿using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WPFExcelReport;
using WPFExcelReport.Helpers;
namespace ReflectionStudio.Controls
{
    public class SDKEYCONV : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string v = value.ToString().Trim();
            string sdkey = (string)parameter;
            if (!ApplicationBase.Instance.DBSDDAT.ContainsKey(sdkey))
                return v;

            DataTable TB = ApplicationBase.Instance.DBSDDAT[sdkey];
            if (TB == null)
                return v;
            string filter = "TRIM(KEY)='" + v.Trim() + "'";
            DataRow[] rows = TB.Select(filter);
            if (rows.Length == 0)
                return v;
            return Helper.GetGB2312Value(rows[0]["SDES"].ToString());
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
    public class LSCONV : IValueConverter
    {
        /// <summary>
        /// IValueConverter.Convert
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string v = value.ToString().Trim();
            string sdkey = (string)parameter;
            if (!ApplicationBase.Instance.DBSDDAT.ContainsKey(sdkey))
                return v;

            DataTable TB = ApplicationBase.Instance.DBSDDAT[sdkey];
            if (TB == null)
                return v;
            string filter = "TRIM(LSLIEFNR)='" + v.Trim() + "'";
            DataRow[] rows = TB.Select(filter);
            if (rows.Length == 0)
                return v;
            return Helper.GetGB2312Value(rows[0]["DES"].ToString());
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
